package com.lg.system.wxmenu.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.lg.utils.R;
import com.lg.wechat.common.annotation.WxAuthen;
import com.lg.wechat.common.base.BaseController;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;

/**
 * <pre>
 *  注意：此contorller 实现WxMpMenuService接口，仅是为了演示如何调用所有菜单相关操作接口，
 *      实际项目中无需这样，根据自己需要添加对应接口即可
 * </pre>
 *
 * @author Binary Wang(https://github.com/binarywang)
 */
@RestController
@RequestMapping("/wxmenu")
public class WxMenuController extends BaseController {

  private String prefix="system/wxmenu/";
  
  @Autowired
  private WxMpService wxMpService;

	@GetMapping("/index")
	public ModelAndView index() throws WxErrorException{
		//WxMpQrCodeTicket ticket = wxService.getQrcodeService().qrCodeCreateLastTicket("longlong");
		//System.out.println(ticket);
		//System.out.println(wxService.getQrcodeService().qrCodePictureUrl(ticket.getTicket()));
		ModelAndView mView=new ModelAndView(prefix+"index");
		return mView;
	}
  
  @PostMapping("/create")
  public R createmenu(String json) throws WxErrorException {
    this.wxMpService.getMenuService().menuCreate(json);
    return R.ok();
  }
  /**
   * <pre>
   * 自定义菜单查询接口
   * 详情请见： https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141014&token=&lang=zh_CN
   * </pre>
   */
  @GetMapping("/get")
  @WxAuthen
  public String menuGet() throws WxErrorException {
    return this.wxMpService.getMenuService().menuGet().toJson();
  }
  

  /**
   * <pre>
   * 自定义菜单删除接口
   * 详情请见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141015&token=&lang=zh_CN
   * </pre>
   */
  @GetMapping("/delete")
  public void menuDelete() throws WxErrorException {
    this.wxMpService.getMenuService().menuDelete();
  }

  
	@GetMapping("/choose/{type}")
	public ModelAndView edit(@PathVariable("type") String type){
		ModelAndView mView=new ModelAndView(prefix+"select_image");
		mView.addObject("type",type );
		return mView;
	}
  


}
